/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.ingsoc2;

import java.awt.event.ActionListener;

/**
 *
 * @author sebastian
 */
public class CalculadoraViewSwing extends javax.swing.JFrame {

    public void mostrarCalculadora(Calculadora calc){
        this.setVisible(true);
        
    }
    
    public void mostrarResultado(String resultado){
        lblResultado.setText(resultado);
        
    }
    
    public String getLblResultado(){
        return lblResultado.getText();
        
    }

    public void mostrarError(String error){
        lblResultado.setText(error);
    }
        
    public void agregarListenerCmdSumar(ActionListener lst){
            cmdSumar.addActionListener(lst);
    }
    
    public void agregarListenerCmdRestar(ActionListener lst){
        cmdRestar.addActionListener(lst);
    }

    public void agregarListenerCmdMultiplicar(ActionListener lst){
        cmdMultiplicar.addActionListener(lst);
    }
    
    public void agregarListenerCmdDividir(ActionListener lst){
        cmdDividir.addActionListener(lst);
    }
        
    public Double getTxtCampo1(){
return Double.parseDouble(txtCampo1.getText());     
    }
        
    public Double getTxtCampo2() throws NumberFormatException{
        return Double.parseDouble(txtCampo2.getText()); 
    }
        
    
        
    /**
     * Creates new form CalculadoraViewSwing
     */
    public CalculadoraViewSwing() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        txtCampo1 = new javax.swing.JTextField();
        txtCampo2 = new javax.swing.JTextField();
        lblResultado = new javax.swing.JLabel();
        cmdSumar = new javax.swing.JButton();
        cmdRestar = new javax.swing.JButton();
        cmdMultiplicar = new javax.swing.JButton();
        cmdDividir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        txtCampo1.setText("0");
        txtCampo1.setMinimumSize(new java.awt.Dimension(20, 28));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(txtCampo1, gridBagConstraints);

        txtCampo2.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(txtCampo2, gridBagConstraints);

        lblResultado.setText("Resultado");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(lblResultado, gridBagConstraints);

        cmdSumar.setText("Sumar");
        cmdSumar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdSumarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(cmdSumar, gridBagConstraints);

        cmdRestar.setText("Restar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(cmdRestar, gridBagConstraints);

        cmdMultiplicar.setText("Multiplicar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(cmdMultiplicar, gridBagConstraints);

        cmdDividir.setText("Dividir");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(cmdDividir, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmdSumarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdSumarActionPerformed
        // TODO add your handling code here:
        
                
    }//GEN-LAST:event_cmdSumarActionPerformed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdDividir;
    private javax.swing.JButton cmdMultiplicar;
    private javax.swing.JButton cmdRestar;
    private javax.swing.JButton cmdSumar;
    private javax.swing.JLabel lblResultado;
    private javax.swing.JTextField txtCampo1;
    private javax.swing.JTextField txtCampo2;
    // End of variables declaration//GEN-END:variables
}
